package com.atguigu.educms.controller;

import com.atguigu.commonutils.result.R;
import com.atguigu.educms.entity.Banner;
import com.atguigu.educms.service.BannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * @author kabuda
 * @create 2023-05-11 19:59
 */
@RestController
@RequestMapping("educms/banner/admin")
public class BannerAdminController {
    @Autowired
    private BannerService bannerService;

    @GetMapping("list/{page}/{limit}")
    public R list(@PathVariable("page") Long page, @PathVariable("limit")Long limit){
      R r=bannerService.pageList(page,limit);
      return r;

    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public R get(@PathVariable String id) {
        Banner banner = bannerService.getById(id);
        return R.ok().data("item", banner);
    }

    @CachePut(value = "banner",key = "'bannerList'")
    @ApiOperation(value = "新增Banner")
    @PostMapping("save")
    public R save(@RequestBody Banner banner) {
        bannerService.save(banner);
        return R.ok();
    }
    @CacheEvict(value = "banner",key = "'bannerList'")
    @ApiOperation(value = "修改Banner")
    @PutMapping("update")
    public R updateById(@RequestBody Banner banner) {
        bannerService.updateById(banner);
        return R.ok();
    }
    @CacheEvict(value = "banner",key = "'bannerList'")
    @ApiOperation(value = "删除Banner")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id) {
        bannerService.removeById(id);
        return R.ok();
    }
}

